home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / pc / windows / qtw_201 / setup / samples / frontrow / frontrow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-19  |  6.4 KB  |  224 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // FRONTROW.C   - QuickTime for Windows
  5. //
  6. //                Version 1.0
  7. //
  8. //                (c) Copyright 1988-1994 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12. #include <windows.h>
  13. #include <commdlg.h>
  14. #include <qtw.h>
  15. #include <dos.h>
  16. #include <direct.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <sys\types.h>
  21. #include <sys\stat.h> 
  22. #include "fileexts.rh"
  23.  
  24. long FAR PASCAL __export WndProc (HWND, UINT, WPARAM, LPARAM);
  25.  
  26. static MovieFile mfMovie;
  27. static Movie mMovie;
  28. static MovieController mcController;
  29. static HWND hWnd;
  30. static char szAppName[] = "FRONTROW";
  31.  
  32.  
  33. // WinMain
  34. // ---------------------------------------------------------------------
  35. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  36.    LPSTR lpszCmdParam, int nCmdShow)
  37. {
  38.     MSG msg;
  39.     WNDCLASS wndclass;
  40.     char szDir[_MAX_DIR];
  41.     char szMovieTitle[_MAX_PATH];
  42.     char szMovie[_MAX_PATH];
  43.     char szFilter[_MAX_PATH];
  44.     OPENFILENAME ofn;
  45.     RECT rcClient, rcMovie;
  46.     LONG lStyle;
  47.     struct _stat st;
  48.     char* p;
  49.  
  50.     // If parameter is missing, look for a movie with the same name
  51.     // as the executable. If this isn't found, use the standard
  52.     // open dialog to get a movie name
  53.  
  54.     if (lstrlen (lpszCmdParam) == 0) {
  55.         GetModuleFileName (hInstance, szMovie, sizeof (szMovie));
  56.         p = strrchr (szMovie, '.');
  57.         strcpy (p, ".MOV");
  58.         if (_stat (szMovie, &st)) {
  59.             _getcwd (szDir, sizeof (szDir));
  60.             szMovie[0] = '\0';
  61.             memset (&ofn, 0, sizeof(OPENFILENAME));
  62.             ofn.lStructSize = sizeof(OPENFILENAME);
  63.             ofn.hwndOwner = 0;
  64.             ofn.lpstrFilter = CommonGetFileFilter (hInstance, (WORD) COMMON_MOVIES_FILEEXT, szFilter, sizeof szFilter);
  65.             ofn.nFilterIndex = 1;
  66.             ofn.lpstrFile = szMovie;
  67.             ofn.nMaxFile = sizeof(szMovie);
  68.             ofn.lpstrFileTitle = szMovieTitle;
  69.             ofn.nMaxFileTitle = sizeof(szMovieTitle);
  70.             ofn.lpstrInitialDir = szDir;
  71.             ofn.lpstrTitle = "Select a Movie to Watch";
  72.             ofn.Flags = OFN_HIDEREADONLY;
  73.             if (GetOpenFileName (&ofn) == 0)
  74.                 return 0;
  75.         }
  76.         _strupr (szMovie);
  77.     }
  78.  
  79.     // Otherwise, treat the command line parameter as the
  80.     // root directory.
  81.  
  82.     else {
  83.         lstrcpy (szMovie, lpszCmdParam);
  84.         _strupr (szMovie);
  85.     }
  86.  
  87.     // Establish links to QuickTime for Windows
  88.  
  89.     if (QTInitialize (NULL)) {
  90.         MessageBox (NULL, "QTInitialize failure", szAppName, MB_OK);
  91.         return 0;
  92.     }
  93.  
  94.     // Allocate memory required for playing movies
  95.  
  96.     if (EnterMovies ()) {
  97.         MessageBox (NULL, "EnterMovies failure", szAppName, MB_OK);
  98.         return 0;
  99.     }
  100.  
  101.     // Instantiate movie
  102.  
  103.     if (OpenMovieFile (szMovie, &mfMovie, OF_READ) != noErr) {
  104.         MessageBox (NULL, "OpenMovieFile failure", szAppName, MB_OK);
  105.         PostQuitMessage (0);
  106.         return 0;
  107.     }
  108.  
  109.     NewMovieFromFile (&mMovie, mfMovie, NULL, NULL, 0, NULL);
  110.     CloseMovieFile (mfMovie);
  111.  
  112.     // Register and create main window
  113.  
  114.     if (!hPrevInstance) {
  115.         wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  116.         wndclass.lpfnWndProc = WndProc;
  117.         wndclass.cbClsExtra = 0;
  118.         wndclass.cbWndExtra = 0;
  119.         wndclass.hInstance = hInstance;
  120.         wndclass.hIcon = LoadIcon (NULL,IDI_APPLICATION);
  121.         wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
  122.         wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
  123.         wndclass.lpszMenuName = NULL;
  124.         wndclass.lpszClassName = szAppName;
  125.         if (!RegisterClass (&wndclass)) {
  126.             MessageBox (NULL, "RegisterClass failure", szAppName, MB_OK);
  127.             return 0;
  128.         }
  129.     }
  130.  
  131.     hWnd = CreateWindow(szAppName, szAppName,
  132.         WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
  133.         CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
  134.  
  135.     if (hWnd == NULL) {
  136.         MessageBox (NULL, "CreateWindow failure", szAppName, MB_OK);
  137.         return 0;
  138.     }
  139.  
  140.     // Instantiate the movie controller
  141.  
  142.     GetMovieBox (mMovie, &rcMovie);
  143.     GetClientRect (GetDesktopWindow (), &rcClient);
  144.     OffsetRect (&rcMovie, -rcMovie.left, -rcMovie.top);
  145.     rcMovie.right *= 2, rcMovie.bottom *= 2;
  146.     OffsetRect (&rcMovie, (rcClient.right - rcMovie.right) / 2,
  147.       (rcClient.bottom - rcMovie.bottom) / 2);
  148.     mcController = NewMovieController (mMovie, &rcMovie,
  149.         mcTopLeftMovie + mcScaleMovieToFit + mcNotVisible, hWnd);
  150.  
  151.     // Make the main window visible
  152.  
  153.     lStyle = GetWindowLong (hWnd, GWL_STYLE);
  154.     lStyle &= ~(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_BORDER | WS_THICKFRAME | WS_DLGFRAME);
  155.     SetWindowLong (hWnd, GWL_STYLE, lStyle);
  156.     ShowWindow (hWnd, SW_SHOWMAXIMIZED);
  157.     UpdateWindow (hWnd);
  158.     SetMovieActive (mMovie, TRUE);
  159.     InvalidateRect (hWnd, &rcMovie, FALSE);
  160.     MCDoAction (mcController, mcActionSetFlags, (LPVOID) mcFlagsUseWindowPalette);
  161.     MCDoAction (mcController, mcActionSetKeysEnabled, (LPVOID) TRUE);
  162.  
  163.     // Play the movie
  164.  
  165.     while (GetMessage (&msg, NULL, 0, 0)) {
  166.         TranslateMessage (&msg);
  167.         DispatchMessage (&msg);
  168.     }
  169.  
  170.     // Destroy movie controller
  171.  
  172.     DisposeMovieController (mcController);
  173.  
  174.     // Destroy movie
  175.  
  176.     DisposeMovie (mMovie);
  177.  
  178.     // Cut the connections to QuickTime for Windows
  179.  
  180.     ExitMovies ();
  181.     QTTerminate ();
  182.  
  183.     // Return to Windows
  184.  
  185.     return msg.wParam;
  186. }
  187.  
  188.  
  189. // WndProc
  190. // ---------------------------------------------------------------------
  191. long FAR PASCAL __export WndProc (HWND hWnd, UINT message, WPARAM wParam,
  192.    LPARAM lParam)
  193. {
  194.     PAINTSTRUCT ps;
  195.  
  196.     // Drive the movie controller
  197.  
  198.     MCIsPlayerMessage (mcController, hWnd, message, wParam, lParam);
  199.  
  200.     // Process the windows message
  201.  
  202.     switch (message) {
  203.  
  204.         // In case we have to paint this movie
  205.  
  206.         case WM_PAINT:
  207.             if (!BeginPaint (hWnd, &ps))
  208.                 return 0;
  209.             EndPaint (hWnd, &ps);
  210.             return 0;
  211.  
  212.         // All done!
  213.  
  214.         case WM_DESTROY:
  215.             PostQuitMessage (0);
  216.             return 0;
  217.  
  218.     }
  219.  
  220.     // Return to Windows
  221.  
  222.     return DefWindowProc (hWnd, message, wParam, lParam);
  223. }
  224.